/*
 * @Author: tanjunyi@doctorwork.com
 * @Date: 2020-04-07 23:00:20
 * @LastEditors: tanjunyi@doctorwork.com
 * @LastEditTime: 2020-04-07 23:18:14
 * @Description: 
 */

var _plugins = {
	"emit": [
		function (a, b, cb) {
			console.log("注册第一个定时器");
			setTimeout(() => {
				console.log('1', a, b);
				cb();
			}, 1000);
		},
		function (a, b, cb) {
			console.log("注册第二个定时器");
			setTimeout(() => {
				console.log('2', a, b);
				cb();
			}, 500)
		}
	]
};

function applyPluginsAsync(type, a, b, callback) {
	var plugin = _plugins[type];
	function excute() {
		var currentFn = plugin.shift();
		if (currentFn) {
			currentFn(a, b, excute);
		}
	}
	excute(a, b, plugin);
}



applyPluginsAsync("emit", 'aaaa', 'bbbbb', function () {
	console.log('end')
});